#pragma once
#include <osg/PrimitiveSet>

#include "Ent.h"

extern osg::Vec3d getPointOfAngle(const double angle, const osg::Vec3d& center, const double radius);

class JsonReader;

struct ArcPrivate;
class Arc2D : public Ent2DCurve
{
	Q_OBJECT
public:
	Arc2D(INode* parent);
	virtual std::shared_ptr<Ent> clone() const override;
	void set(const osg::Vec3d &center, const double radius, const double startAngle, const double endAngle);
	void setCircle(const osg::Vec3d &center, const double radius);
	void setColor(const osg::Vec4 &color);
	const osg::Vec4& color() const;
	const osg::Vec3d& center() const;
	double radius() const;
	float startAngle() const;
	float endAngle() const;
	virtual void update3D() override;
	virtual osg::Node* getRep3D() const override;
	virtual void setSelected(bool val) override;
	virtual void save(QJsonObject &json) const;
	virtual void load(const QJsonObject& json, JsonReader& reader);
	virtual std::vector<osg::Vec3d> handles() const override;
	virtual void move(const osg::Vec3d& offset) override;
	virtual void scale(const osg::Vec3d& center, double scale) override;
	virtual void mirror(const osg::Vec3d& start, const osg::Vec3d& end) override;
	virtual void stretch(int index, const osg::Vec3d &offset) override;
	virtual void copy(const Ent& ent) override;
	virtual void rotate(const double angle, const osg::Vec2d& basePoint) override;
	virtual std::vector<Handle(Geom2d_Curve)> getCurve2d() const override;
	virtual std::shared_ptr<Ent2DCurve> extend(bool front, double param, const gp_Pnt2d& point) const;
	virtual std::vector<std::shared_ptr<Ent2DCurve>> trim(const SectionParam& from, const SectionParam& to) const;
	void normalize();
	virtual bool offset(double offset);
	virtual bool offset(double offset, const osg::Vec3d& offsetSide);
	virtual std::vector<std::shared_ptr<Ent3DCurve>> to3d();
	LEAF_METHODS;

protected:
	void calHandles() const;

	ArcPrivate* d_ptr;
};
